<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="李愧愧">
    <title></title>
    <style>

    </style>
</head>

<body>

    <script>
        var str= prompt('请输入字符串：');
        var count = 0;
        console.log(str, typeof str);
        for (var i = 0; i <str.length; i++) {
            if (str[i] == 'a') {
                count++;
            }
        }
        alert('a出现' + count + '次')
    </script>
</body>
<ml>